package com.yc.wxcontroller;

import com.yc.entity.Attendance;
import com.yc.entity.Schedule;
import com.yc.entity.StudentInfo;
import com.yc.service.AttendanceService;
import com.yc.service.ScheduleService;
import com.yc.service.StudentInfoService;
import com.yc.vo.Result;
import com.yc.vo.StudentAttendanceRecord;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2023/7/24 11:03
 */
@Api("微信管理学生控制器")
//@RestController
//@RequestMapping("/wx/studentInfo")
public class WXStudentInfoController {
    @Resource
    StudentInfoService studentInfoService;
    @Resource
    AttendanceService attendanceService;
    @Resource
    ScheduleService scheduleService;

    @ApiOperation("通过cid查询班级所在学生")
    @GetMapping("/get/{username}")
    public Result selectStudentInfoByCid(@ApiParam(name = "username", value = "老师工号", required = true)
                                             @PathVariable("username") String username,
                                         @RequestParam String cid){
        // 查询学生前判断是否有考勤记录 有考勤记录就联合记录表 将 考勤详情查出来 没有就默认状态为1
        Schedule schedule = scheduleService.selectScheduleByCidAndDate(username, cid);
        Integer attId = attendanceService.selectAttendanceByScheduleId(schedule.getId() + "");
        List<StudentAttendanceRecord> studentInfoList;
        Result result = new Result();
        Map<String, Object> data = new HashMap<>();
        if (attId == null || attId <= 0){
            studentInfoList = studentInfoService.selectStudentInfoByCid(schedule.getId() + "", cid);
            data.put("studentInfoList", studentInfoList);
            data.put("attId", 0);
        }else {
            studentInfoList = attendanceService.selectStudentByAttId(attId + "");
            data.put("studentInfoList", studentInfoList);
            data.put("attId", attId);
        }
        result.setData(data);
        return result;
    }
}
